#获取传入目录的下面的所有文件和文件夹

import os

dict1 = {}


def gci(filepath):
    files = os.listdir(filepath)
    for fi in files:
        fi_d = os.path.join(filepath, fi)
        if os.path.isdir(fi_d):
            if not(dict1.__contains__(fi_d.replace('\\', '\\\\'))):
                dict1[fi_d.replace('\\', '\\\\')] = []
            gci(fi_d)
        else:
            if os.path.isfile(fi_d) and os.path.splitext(fi_d)[1] == '.txt':
                if not(dict1.__contains__(os.path.dirname(fi_d).replace('\\', '\\\\'))):
                    dict1[os.path.dirname(fi_d).replace('\\', '\\\\')] = [fi_d.replace('\\', '\\\\')]
                else:
                    key1 = dict1[os.path.dirname(fi_d).replace('\\', '\\\\')]
                    key1.append(fi_d.replace('\\', '\\\\'))


def get_all_file(files):
    if not files.strip():
        files = 'F:\\test1'
    gci(files)
    return dict1


# if __name__ == '__main__':
#     gci('F:\\test1')
#     print(dict1.keys())
